<?php
/**
 * @version		$Id: default.php 21322 2011-05-11 01:10:29Z dextercowley $
 * @package		Joomla.Site
 * @subpackage	mod_login
 * @copyright	Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */

// no direct access
defined('_JEXEC') or die;


JHtml::_('behavior.keepalive');
$user =  &JFactory::getUser();

$session_vipcard =& JFactory::getSession();
$session_vipcard_id =  $session_vipcard->getId();

$com_layout = JRequest::getVar('layout');
$components = JRequest::getVar('option');

$userPoint = $_SESSION[$user->id.'p'];

$lang =& JFactory::getLanguage();
if($lang->getTag() == 'vi-VN')
	$style="style='background: url(./templates/wrd/images/add_to_cart_module_vi-VN.png) no-repeat'";

?>

<?php if($user->id != 0): ?>
	<?php if($components != 'com_promotions'): ?>
		<script type="text/javascript">
		jQuery(window).load(function() {
			var scItems = [];
		    if(jQuery.cookie("<?php echo md5($session_vipcard_id); ?>") != ""){
		    	var data_dec = decodeCookies(jQuery.cookie("<?php echo md5($session_vipcard_id); ?>"));
        		scItems = json_decode(data_dec);
		    }
		    var currentUserPoint = "<?php echo $userPoint; ?>";    
		    var totalPointSubtract = currentUserPoint;
		    var totalPoint = 0;
	        var totalCash = 0;
	        
		    if(scItems != null && scItems.length > 0){
	            jQuery("#cart-items").html("");
	            var total_item = 0;
	            for(var i=0; i<scItems.length; i++){
	            	totalPoint = parseInt(totalPoint) + parseInt(scItems[i].point)*parseInt(scItems[i].qty) + parseInt(scItems[i].pointx)*parseInt(scItems[i].qty);
	                totalCash = parseInt(totalCash) + parseInt(scItems[i].cash)*parseInt(scItems[i].qty); 
	                total_item = total_item + parseInt(scItems[i].qty);
	            }
	
	            totalPointSubtract = parseInt(currentUserPoint) - parseInt(totalPoint);
	            
	            var html = "<table cellpadding=\"0\" cellspacing=\"0\"><tbody>";
	            html += "<tr><td width=\"50%\" align=\"right\"><?php echo JText::_('WRD_LEFT_MENU_YOUR_POINTS'); ?> </td><td width=\"50%\" align=\"left\">"+number_format(totalPointSubtract, 0,',',',')+"</td></tr>";
	            html += "<tr><td width=\"50%\" align=\"right\"><?php echo JText::_('WRD_LEFT_MENU_TOTAL_POINTS'); ?> </td><td width=\"50%\" align=\"left\">"+number_format(totalPoint, 0,',',',')+"</td></tr>";
	            
	            html += "<tr><td align=\"right\"><?php echo JText::_('WRD_LEFT_MENU_TOTAL_CASH'); ?></td><td align=\"left\">"+number_format(totalCash, 0,',','.')+"</td></tr>";
	            html += "</tbody></table>";
	
	            if(total_item <= 1)
	            	jQuery("#cart-items").html('<span class="item_count">'+total_item+'</span><span class="item_text"><?php echo JText::_('WRD_LEFT_MENU_ITEM_IN_YOUR_CART'); ?></span>');
	            else
	            	jQuery("#cart-items").html('<span class="item_count">'+total_item+'</span><span class="item_text"><?php echo JText::_('WRD_LEFT_MENU_ITEMS_IN_YOUR_CART'); ?></span>');
	            
	            jQuery("#invoice-details").html(html);
	            jQuery("#redeem-now-link").show();
	            
	        }else{
	        	var html = "<table  cellpadding=\"0\" cellspacing=\"0\"><tbody>";
	            html += "<tr><td width=\"50%\" align=\"right\"><?php echo JText::_('WRD_LEFT_MENU_YOUR_POINTS') ?></td><td width=\"50%\" align=\"right\">"+number_format(currentUserPoint, 0,'.',',')+"</td></tr>";
	            html += "<tr><td width=\"50%\" align=\"right\"><?php echo JText::_('WRD_LEFT_MENU_TOTAL_POINTS') ?> </td><td width=\"50%\" align=\"right\">"+number_format(0, 0,',',',')+"</td></tr>";
	            
	            html += "<tr><td align=\"right\"><?php echo JText::_('WRD_LEFT_MENU_TOTAL_CASH'); ?> </td><td align=\"right\">"+number_format(0, 0,',',',')+"</td></tr>";
	            html += "</tbody></table>";
	            
				jQuery("#cart-items").html('<span class="item_count">0</span><span class="item_text"><?php echo JText::_('WRD_LEFT_MENU_ITEMS_IN_YOUR_CART'); ?></span>');
	            
				jQuery("#invoice-details").html(html);
				jQuery("#redeem-now-link").hide();
	        }
		});
		
		
		function decodeCookies(obj){
	    	var data ;
	    	jQuery.ajax({
	    		async: false,
	            type: "post",
	            url : "index.php?option=com_promotions&task=decryptcart",
	            data: "params="+(obj),
	            success: function(json){ 
	                var result = eval(json);
	                
	                if (result.success == true)
	                {
	                	data =  result.data;
	                }
	                else
	                {
	                	console.log('can not decrypt');
	                }
	            }
	        });
	        return data;
	    }
		</script>
	<?php endif; ?>
<?php endif; ?>

<?php if($components == 'com_wrd'): ?>
<ul class="right-menu" role="menu">
	<?php if($user->id != 0): ?>
	<li class="menuheader">
		<i class="fa fa-caret-square-o-down"></i>
			<?php echo JText::_('WRD_LEFT_MENU_MYACCOUNT') ?>
	</li>
	<li class="menuitem">
		<a class="l_<?php echo JFilterOutput::stringURLSafe('MY ACCOUNT'); ?>" 
			href="<?php echo JRoute::_('index.php?option=com_wrd&view=profile&layout=default&id=1:'.JFilterOutput::stringURLSafe('MY ACCOUNT').'&Itemid=170'); ?>">
			<i class="fa fa-caret-right"></i>
			<?php echo JText::_('WRD_LEFT_MENU_MYACCOUNT') ?>
		</a>
	</li>
	<li class="menuitem">
		<a class="l_<?php echo JFilterOutput::stringURLSafe('MY POINTS'); ?>" 
			href="<?php  echo JRoute::_('index.php?option=com_wrd&view=profile&layout=myaccount&id=0:'.JFilterOutput::stringURLSafe('MY POINTS').'&Itemid=119'); ?>">
			<i class="fa fa-caret-right"></i>
			<?php echo JText::_('WRD_LEFT_MENU_MYPOINT') ?>
		</a>
	</li>
	<li class="menuitem">
		<a class="l_<?php echo JFilterOutput::stringURLSafe('Change Password'); ?>" 
			href="<?php  echo JRoute::_('index.php?option=com_wrd&view=profile&layout=reset&id=0:'.JFilterOutput::stringURLSafe('CHANGE PASSWORD').'&Itemid=119'); ?>">
			<i class="fa fa-caret-right"></i>
			<?php echo JText::_('WRD_LEFT_CHANGE_PASSWORD') ?>
		</a>
	</li>
	<?php endif; ?>
	<li class="menuheader">
		<i class="fa fa-caret-square-o-down"></i>
			<?php echo JText::_('WRD_LEFT_MENU_RESOURCES') ?>
	</li>
	<li class="menuitem">
		<a class="l_<?php echo JFilterOutput::stringURLSafe('PROMOTIONS'); ?>" 
			href="<?php echo JRoute::_('index.php?option=com_content&view=category&layout=blog&id=43:'.JFilterOutput::stringURLSafe('PROMOTIONS').'&Itemid=184') ?>">
			<i class="fa fa-caret-right"></i>
			<?php echo JText::_('WRD_LEFT_MENU_PROMOTIONS') ?>
		</a>
	</li>
	<li class="menuitem">
		<a class="l_<?php echo JFilterOutput::stringURLSafe('NEWS'); ?>" 
			href="<?php echo JRoute::_('index.php?option=com_content&view=category&layout=blog&id=44:'.JFilterOutput::stringURLSafe('NEWS').'&Itemid=220') ?>">
			<i class="fa fa-caret-right"></i>
			<?php echo JText::_('WRD_LEFT_MENU_NEWS') ?>
		</a>
	</li>
	<li class="menuitem" style="">
		<a class="l_<?php echo JFilterOutput::stringURLSafe('EVENTS'); ?>" 
			href="<?php echo JRoute::_('index.php?option=com_content&view=category&layout=blog&id=12:'.JFilterOutput::stringURLSafe('EVENTS').'&Itemid=181') ?>">
			<i class="fa fa-caret-right"></i>
			<?php echo JText::_('WRD_LEFT_MENU_EVENTS') ?>
		</a>
	</li>
	<li class="menuheader">
		<i class="fa fa-caret-square-o-down"></i>
		<?php echo JText::_('WRD_LEFT_MENU_MY_GIFT_REDEMPTION') ?>
	</li>
	<?php foreach($categories as $item): ?>
		<li class="menuitem">
			<a class="l_<?php echo JFilterOutput::stringURLSafe($item->title); ?>" 
				href="<?php echo JRoute::_('index.php?option=com_promotions&view=redemptions&id='.$item->id.':'.JFilterOutput::stringURLSafe($item->title)); ?>">
				<i class="fa fa-caret-right"></i>
				<?php echo JText::_(WrdHelper::stringURLSafeAliasLang('WRD_LEFT_MENU_'.$item->title)); ?>
			</a>
		</li>
	<?php endforeach; ?>
	
	<?php if($user->id != 0): ?>
	<li class="menuitem">
		<a class="l_recommend" 
		href="<?php echo JRoute::_('index.php?option=com_promotions&view=redemptions&id=recommend'); ?>">
			<i class="fa fa-caret-right"></i>
			<?php echo JText::_('WRD_LEFT_MENU_RECOMMENDATION_FOR_YOU') ?>
		</a>
	</li>
	<?php endif; ?>
</ul>
	<?php if($user->id != 0): ?>
		<?php if($com_layout != 'shoppingcart'): ?>
			<div class="card_holder">
				<div class="shopping-cart">
			        <div class="header_text"><?php echo JText::_('WRD_LEFT_MENU_ADD_TO_CART') ?></div>
			        <ul class="cart-items" id="cart-items">
			        </ul>
			        <div id="invoice-details"></div>
			        <div id="redeem-now">
			            <a id="redeem-now-link" <?php echo $style; ?>
			            	href="<?php echo JRoute::_('index.php?option=com_promotions&layout=shoppingcart&view=redemptions&Itemid=112'); ?>"><?php echo JText::_('WRD_LEFT_MENU_REDEEMP_NOW') ?></a>
			        </div>
			    </div>
			</div>
		<?php endif; ?>
	<?php endif;?>
<?php elseif($components == 'com_content'):?>
<ul class="right-menu" role="menu">
	<li class="menuheader">
		<i class="fa fa-caret-square-o-down"></i>
		<?php echo JText::_('WRD_LEFT_MENU_RESOURCES') ?>
	</li>
	<li class="menuitem">
		<a class="l_<?php echo JFilterOutput::stringURLSafe('PROMOTIONS'); ?>" href="<?php echo JRoute::_('index.php?option=com_content&view=category&layout=blog&id=43:'.JFilterOutput::stringURLSafe('PROMOTIONS').'&Itemid=184') ?>">
			<?php echo JText::_('WRD_LEFT_MENU_PROMOTIONS') ?></a>
	</li>
	<li class="menuitem">
		<a class="l_<?php echo JFilterOutput::stringURLSafe('NEWS'); ?>" href="<?php echo JRoute::_('index.php?option=com_content&view=category&layout=blog&id=44:'.JFilterOutput::stringURLSafe('NEWS').'&Itemid=220') ?>">
			<?php echo JText::_('WRD_LEFT_MENU_NEWS') ?></a>
	</li>
	<li class="menuitem">
		<a class="l_<?php echo JFilterOutput::stringURLSafe('EVENTS'); ?>" href="<?php echo JRoute::_('index.php?option=com_content&view=category&layout=blog&id=12:'.JFilterOutput::stringURLSafe('EVENTS').'&Itemid=181') ?>">
			<?php echo JText::_('WRD_LEFT_MENU_EVENTS') ?></a>
	</li>
	<?php if($user->id != 0): ?>
	<li class="menuheader">
		<i class="fa fa-caret-square-o-down"></i>
		<?php echo JText::_('WRD_LEFT_MENU_MYACCOUNT') ?>
	</li>
	<li class="menuitem">
		<a class="l_<?php echo JFilterOutput::stringURLSafe('MY ACCOUNT'); ?>" 
			href="<?php echo JRoute::_('index.php?option=com_wrd&view=profile&layout=default&id=1:'.JFilterOutput::stringURLSafe('MY ACCOUNT').'&Itemid=170'); ?>">
			<?php echo JText::_('WRD_LEFT_MENU_MYACCOUNT') ?></a>
	</li>
	<li class="menuitem">
		<a class="l_<?php echo JFilterOutput::stringURLSafe('MY POINTS'); ?>" 
			href="<?php  echo JRoute::_('index.php?option=com_wrd&view=profile&layout=myaccount&id=0:'.JFilterOutput::stringURLSafe('MY POINTS').'&Itemid=119'); ?>">
			<?php echo JText::_('WRD_LEFT_MENU_MYPOINT') ?></a>
	</li>
	<li class="menuitem">
		<a class="l_<?php echo JFilterOutput::stringURLSafe('Change Password'); ?>" 
			href="<?php  echo JRoute::_('index.php?option=com_wrd&view=profile&layout=reset&id=0:'.JFilterOutput::stringURLSafe('CHANGE PASSWORD').'&Itemid=119'); ?>">
			<?php echo JText::_('WRD_LEFT_CHANGE_PASSWORD') ?></a>
	</li>
	<?php endif; ?>
	<li class="menuheader">
		<i class="fa fa-caret-square-o-down"></i>
		<?php echo JText::_('WRD_LEFT_MENU_MY_GIFT_REDEMPTION') ?>
	</li>
	<?php foreach($categories as $item): ?>
		<li class="menuitem">
			<a class="l_<?php echo JFilterOutput::stringURLSafe($item->title); ?>" href="<?php echo JRoute::_('index.php?option=com_promotions&view=redemptions&id='.$item->id.':'.JFilterOutput::stringURLSafe($item->title)); ?>">
				<i class="fa fa-caret-right"></i>
				<?php echo JText::_(WrdHelper::stringURLSafeAliasLang('WRD_LEFT_MENU_'.$item->title)); ?>
			</a>
		</li>
	<?php endforeach; ?>
	
	<?php if($user->id != 0): ?>
	<li class="menuitem">
		<a class="l_recommend" href="<?php echo JRoute::_('index.php?option=com_promotions&view=redemptions&id=recommend'); ?>">
			<i class="fa fa-caret-right"></i>
			<?php echo JText::_('WRD_LEFT_MENU_RECOMMENDATION_FOR_YOU') ?>
		</a>
	</li>
	<?php endif; ?>
</ul>
	<?php if($user->id != 0): ?>
		<?php if($com_layout != 'shoppingcart'): ?>
			<div class="card_holder">
				<div class="shopping-cart">
			        <div class="header_text"><?php echo JText::_('WRD_LEFT_MENU_ADD_TO_CART') ?></div>
			        <ul class="cart-items" id="cart-items">
			        </ul>
			        <div id="invoice-details"></div>
			        <div id="redeem-now">
			            <a id="redeem-now-link" <?php echo $style; ?>
			            	href="<?php echo JRoute::_('index.php?option=com_promotions&layout=shoppingcart&view=redemptions&Itemid=112'); ?>">
			            	<?php echo JText::_('WRD_LEFT_MENU_REDEEMP_NOW') ?>
			            	</a>
			        </div>
			    </div>
			</div>
		<?php endif; ?>
	<?php endif;?>
	
<?php elseif($components == 'com_promotions'): ?>

	<?php if($user->id != 0): ?>
		<?php if($com_layout != 'shoppingcart'): ?>
			<div class="card_holder">
				<div class="shopping-cart">
			        <div class="header_text"><?php echo JText::_('WRD_LEFT_MENU_ADD_TO_CART') ?></div>
			        <ul class="cart-items" id="cart-items">
			        </ul>
			        <div id="invoice-details"></div>
			        <div id="redeem-now">
			            <a id="redeem-now-link" <?php echo $style; ?>
			            	href="<?php echo JRoute::_('index.php?option=com_promotions&layout=shoppingcart&view=redemptions&Itemid=112'); ?>">
			            	<?php echo JText::_('WRD_LEFT_MENU_REDEEMP_NOW') ?>
			            	</a>
			        </div>
			    </div>
			</div>
		<?php endif; ?>
	<?php endif;?>
<ul class="right-menu" role="menu">
	<li class="menuheader">
		<i class="fa fa-caret-square-o-down"></i>
		<?php echo JText::_('WRD_LEFT_MENU_MY_GIFT_REDEMPTION') ?>
	</li>
	<?php foreach($categories as $item): ?>
		<li class="menuitem">
			<a class="l_<?php echo JFilterOutput::stringURLSafe($item->title); ?>" 
				href="<?php echo JRoute::_('index.php?option=com_promotions&view=redemptions&id='.$item->id.':'.JFilterOutput::stringURLSafe($item->title)); ?>">
				<i class="fa fa-caret-right"></i>
				<?php echo JText::_(WrdHelper::stringURLSafeAliasLang('WRD_LEFT_MENU_'.$item->title)); ?>
			</a>
		</li>
	<?php endforeach; ?>
	
	<?php if($user->id != 0): ?>
	<li class="menuitem">
		<a class="l_recommend" 
			href="<?php echo JRoute::_('index.php?option=com_promotions&view=redemptions&id=recommend'); ?>">
			<i class="fa fa-caret-right"></i>
			<?php echo JText::_('WRD_LEFT_MENU_RECOMMENDATION_FOR_YOU') ?>
		</a>
	</li>
	<?php endif; ?>
	<?php if($user->id != 0): ?>
	<li class="menuheader">
		<i class="fa fa-caret-square-o-down"></i>
		<?php echo JText::_('WRD_LEFT_MENU_MYACCOUNT') ?>
	</li>
	<li class="menuitem">
		<a class="l_<?php echo JFilterOutput::stringURLSafe('MY ACCOUNT'); ?>" 
			href="<?php echo JRoute::_('index.php?option=com_wrd&view=profile&layout=default&id=1:'.JFilterOutput::stringURLSafe('MY ACCOUNT').'&Itemid=170'); ?>">
			<i class="fa fa-caret-right"></i>
			<?php echo JText::_('WRD_LEFT_MENU_MYACCOUNT') ?>
		</a>
	</li>
	<li class="menuitem">
		<a class="l_<?php echo JFilterOutput::stringURLSafe('MY POINTS'); ?>" 
			href="<?php  echo JRoute::_('index.php?option=com_wrd&view=profile&layout=myaccount&id=0:'.JFilterOutput::stringURLSafe('MY POINTS').'&Itemid=119'); ?>">
			<i class="fa fa-caret-right"></i>
			<?php echo JText::_('WRD_LEFT_MENU_MYPOINT') ?>
		</a>
	</li>
	<li class="menuitem">
		<a class="l_<?php echo JFilterOutput::stringURLSafe('Change Password'); ?>" 
			href="<?php  echo JRoute::_('index.php?option=com_wrd&view=profile&layout=reset&id=0:'.JFilterOutput::stringURLSafe('CHANGE PASSWORD').'&Itemid=119'); ?>">
			<i class="fa fa-caret-right"></i>
			<?php echo JText::_('WRD_LEFT_CHANGE_PASSWORD') ?>
		</a>
	</li>
	<?php endif; ?>
	<li class="menuheader">
		<i class="fa fa-caret-square-o-down"></i>
		<?php echo JText::_('WRD_LEFT_MENU_RESOURCES') ?>
	</li>
	<li class="menuitem">
		<a class="l_<?php echo JFilterOutput::stringURLSafe('PROMOTIONS'); ?>" 
			href="<?php echo JRoute::_('index.php?option=com_content&view=category&layout=blog&id=43:'.JFilterOutput::stringURLSafe('PROMOTIONS').'&Itemid=184') ?>">
			<i class="fa fa-caret-right"></i>
			<?php echo JText::_('WRD_LEFT_MENU_PROMOTIONS') ?>
		</a>
	</li>
	<li class="menuitem">
		<a class="l_<?php echo JFilterOutput::stringURLSafe('NEWS'); ?>" 
			href="<?php echo JRoute::_('index.php?option=com_content&view=category&layout=blog&id=44:'.JFilterOutput::stringURLSafe('NEWS').'&Itemid=220') ?>">
			<i class="fa fa-caret-right"></i>
			<?php echo JText::_('WRD_LEFT_MENU_NEWS') ?>
		</a>
	</li>
	<li class="menuitem">
		<a class="l_<?php echo JFilterOutput::stringURLSafe('EVENTS'); ?>" 
			href="<?php echo JRoute::_('index.php?option=com_content&view=category&layout=blog&id=12:'.JFilterOutput::stringURLSafe('EVENTS').'&Itemid=181') ?>">
			<i class="fa fa-caret-right"></i>
			<?php echo JText::_('WRD_LEFT_MENU_EVENTS') ?>
		</a>
	</li>
</ul>
<?php endif;?>

